/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bakenote.core;

import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.List.ItemIterator;

//import java.util.Iterator;
import java.util.UUID;

/**
 * @author lello
 */
public class RecipeGroup {

    // This array contains the list of all the formulae actually loaded
    // by the program. It is accessible in the entire program.
    private List<Recipe> recipeList = new ArrayList<Recipe>();
    private UUID uuid = null;
    private String name = null;

    public RecipeGroup() {
    }

    public RecipeGroup(String name) {
        this.name = name;
    }

    public Recipe getRecipe(int i) {
        return recipeList.get(i);
    }

    /**
     * Check wheter the recipe defined by the UUID is already member of the group
     * @param UUID
     * @return
     */
    public boolean contains(String UUID) {
        boolean found = false;
        if (!recipeList.isEmpty()) {
            ItemIterator<Recipe> iterator = (ItemIterator<Recipe>) recipeList.iterator();
            while (!found && iterator.hasNext()) {
                Recipe recipe = iterator.next();
                if (recipe.getUUID().equals(UUID)) {
                    found = true;
                }
            }
        }
        return found;
    }

    public String getUUID() {
        return uuid.toString();
    }

    public void setUUID(String s) {
        uuid = UUID.fromString(s);
    }

    public void createUUID() {
        uuid = UUID.randomUUID();
        //System.out.println("Create Key " + uuid);
    }

    public String getName() {
        return name;
    }

    public void setName(String n) {
        name = n;
    }

    public List<Recipe> getList() {
        return recipeList;
    }

    public void add(Recipe r) {
        recipeList.add(r);
    }

    public void remove(Recipe r) {
        recipeList.remove(r);
    }
}
